package com.example.jdbc.model;


import lombok.Data;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Copyright(C), 2020-2021, AmbroseCdMeng
 * FileName:    User
 * Author:      AmbroseCdMeng
 * Date:        2021/1/2815:00
 * Description: 测试实体类 User，实现 RowMapper 类，重写 mapRow 方法，以便于实体字段和数据表字段映射
 * History:
 * <author>     <time>      <version>       <desc>
 * 作者姓名     修改时间        版本号           描述
 */
@Data
public class User implements RowMapper<User> {
    private int id;
    private String username;
    private String password;

    // 重写 mapRow 方法
    @Override
    public User mapRow(ResultSet resultSet, int i) throws SQLException {
        User user = new User();
        user.setId(resultSet.getInt("id"));
        user.setPassword(resultSet.getString("password"));
        return user;
    }
}
